<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="./dist/jquery.validate.js"></script>
  <script src="./dist/localization/messages_zh.js"></script>
</head>

<body>
  <form action="">
    <ul>
      <li><label for="userName">user name:<input type="text" name="userName" id="userName"/></li>
      <li><label for="email">E-mail:<input type="email" name="email" id="email"/></li>
      <li><label for="pwd">pwd:<input type="password" name="pwd" id="pwd"/></li>
      <li><label for="colowd">colowd:<input type="password" name="colpwd" id="colpwd"/></li>
      <li><input type="submit"></li>
    </ul>
  </form>
  <script>
    $(function(){
      $('form').validate({
        //debug模式 验证完成后不提交表单
        debug:true,
        //验证规则
        rules:{
          userName:{
            required:true,
            minlength:4,
            maxlength:8,
          },
          email:{
            //email ，url ，date ，number 有效数字，digits 只能输入数字（整数） ，creditcard 信用卡
            required:true,
            email:true
          },
          pwd:{
            required:true,
            minlength:6,
            maxlength:20,
          },
          colpwd:{
            required:true,
            equalTo:'#pwd'
          }
        },
        //提示信息
        messages:{
          userName:{
            required:'请输入用户名',
          },
          email:{
            required:'请输邮箱',
          },
          colpwd:{
            equalTo:'两次输入不一致'
          }
        }
      })
    })
  </script>
</body>

</html>